<!DOCTYPE html>
<html>

<?php
	session_start();
	if(isset($_SESSION['id'], $_SESSION['vorname'], $_SESSION['name'])){
		$id = $_SESSION['id'];
		$vorname = $_SESSION['vorname'];
		$name = $_SESSION['name'];
		$b_date = $_SESSION['b_date'];
		$loc = $_SESSION['location'];
		$image = $_SESSION['image'];
	}else{
		header("location:index.php");
	}
	function get_name(){
		return $_SESSION['name'];
	}
?>

<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<link rel="stylesheet" type="text/css" href="./css/index.css">
<link href='./images/favicon.ico' rel='shortcut icon' type='image/png'>
<title>Profile</title>
</head>

<body id="fondo">
	<div id="cuerpo">
	<fieldset style="width: 1000px color: #FFF">
		<?php
			include 'header.php';
		?>

		<div id="subcuerpo">
			<table>
				<form method="POST" action="change.php">
				<tr>
					<td id="principal" colspan='2'><h2>Personal data (empty fields won't change)</h2></td>
				</tr>
				<tr>
					<td width='150px' style="text-align:right">Avatar: </td><td><img width="120" height="120"src='./images/<?php echo $id?>.jpg'></td>
				</tr>
				<tr>
					<td width='150px' style="text-align:right">ID: </td><td><input type="text" id="id" name="id" value="<?php echo $id; ?>"></td>
				</tr>
				<tr>
					<td width='150px' style="text-align:right">Vorname: </td><td><input type="text" id="vorname" name="vorname" value="<?php echo $vorname; ?>"></td>
				</tr>
				<tr>
					<td width='150px' style="text-align:right">Name: </td><td><input type="text" id="name" name="name" value="<?php echo $name; ?>"></td>
				</tr>
				<tr>
					<td width='150px' style="text-align:right">Birth date: </td><td><input type="date" id="b_date" name="birth_date" value="<?php echo $b_date; ?>"></td>
				</tr>
				<tr>
					<td width='150px' style="text-align:right">Location: </td><td><input type="text" id="loc" name="location" value="<?php echo $loc; ?>"></td>
				</tr>
				<tr>
					<td width='150px' style="text-align:right">New password: </td><td><input type="password" name="pwd"></td>
				</tr>
				<tr>
					<td width='150px' style="text-align:right">Confirm new password: </td><td><input type="password" name="cpwd"></td>
				</tr>
				<tr>
					<td></td><td style="text-align:left"><input id="button" type="submit" name="submit" value="Confirm"></td>
				</tr>
				<tr>
					<td></td><td id="cambios" style="visibility:hidden; color:red">Your changes were saved</td>
				</tr>
				</form>
			</table>
		</div>
	<?php
		include 'footer.php';
	?>
	</div>

<script type="text/javascript">
	var cambio = "<?php
						if(isset($_SESSION['cambios']) && $_SESSION['cambios']=="si"){
							$_SESSION['cambios'] = 'no';
							echo 'true';
						}else{
							echo 'false';
						}
					?>";

	if(cambio == "true"){
		document.getElementById("cambios").style.visibility="visible";
	}
</script>


</body>

</html>